package com.mico.example.springboot.jpa.multi.config;

import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;

import javax.sql.DataSource;

@Configuration
public class DataSourceConfig {
//    @Bean(name = "primaryDataSource")
//    @Qualifier("primaryDataSource")
//    @ConfigurationProperties(prefix="spring.datasource.primary")
//    public DataSource primaryDataSource() {
//        return DataSourceBuilder.create().build();
//    }
    @Primary
    @Bean
    @ConfigurationProperties(prefix="spring.datasource.primary")
    public DataSourceProperties primaryDatasourceProperties(){
        return new DataSourceProperties();
    }


    @Bean
    DataSource primaryDataSource() {
        return primaryDatasourceProperties().initializeDataSourceBuilder().build();
    }


    @Bean
    @ConfigurationProperties(prefix="spring.datasource.secondary")
    public DataSourceProperties secondaryDatasourceProperties(){
        return new DataSourceProperties();
    }


    @Bean
    @ConfigurationProperties(prefix="spring.datasource.secondary")
    DataSource secondaryDataSource() {
        return secondaryDatasourceProperties().initializeDataSourceBuilder().build();
    }
//    @Bean(name = "secondaryDataSource")
//    @Qualifier("secondaryDataSource")
//    @Primary
//    @ConfigurationProperties(prefix="spring.datasource.secondary")
//    public DataSource secondaryDataSource() {
//        return DataSourceBuilder.create().build();
//    }
}